package com.wanmait.shoppingsys.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.wanmait.shoppingsys.util.DbHelper;
import com.wanmait.shoppingsys.vo.Province;

public class ProvinceDAO {
private static ProvinceDAO provinceDAO;
private ProvinceDAO()
{
	
}
public static ProvinceDAO getDAO()
{
	if(provinceDAO==null)
	{
		provinceDAO=new ProvinceDAO();
	}
	return provinceDAO;
}

public List<Province> finddAll(){
	ArrayList<Province> provinces=new ArrayList<Province>();
	
	String sql="select * from province";
	
	Connection conn = DbHelper.getConn();
	PreparedStatement ps = null;
	ResultSet rs = null;
	try
	{
		ps = conn.prepareStatement(sql);
		rs = ps.executeQuery();
		while(rs.next()) {
			Province province=new Province();
			
			province.setId(rs.getInt("id"));
			province.setName(rs.getString("name"));
		}
	}
	 catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			DbHelper.close(rs, ps, conn);
		}
	return provinces;
}
}
